<!DOCTYPE html>
{extend name="common/application" /}
{block name="title"}<title>个人中心-我的订单</title>{/block}
{block name="css"}
<link rel="stylesheet" type="text/css" href="_CSS_/help.css"/>
<link rel="stylesheet" type="text/css" href="_CSS_/order.css"/>
<style type="text/css">
    .nodatas{text-align: center;padding: 100px 0;}
    .nodatas img{display: inline-block;margin-top: 100px;margin-bottom: 20px;}
</style>
{/block}


<!-- 主体内容 -->
{block name="content"}
<div class="main">
    <div class="mainBody normalBox clearfix">
        <!--左菜单-->
        <ul class="menuList fl">
            <li>
                <a class="menuItem dropBg" href="personal.html"><span class="icons icon-account"></span>账户管理</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="personal.html">个人资料</a>
                    <a class="menuchildItem" href="javascript:;">实名认证</a>
                    <a class="menuchildItem" href="javascript:;">账户安全</a>
                </div>
            </li>
            <li class="showChild">
                <a class="menuItem dropBg" href="order.html"><span class="icons icon-order"></span>我的订单</a>
                <div class="childMenu">
                    <a class="menuchildItem activeMenu" href="order.html">我的订单</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="collect_news.html"><span class="icons icon-collection"></span>我的收藏</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="collect_news.html">资讯收藏</a>
                    <a class="menuchildItem" href="collect_course.html">课程收藏</a>
                    <a class="menuchildItem" href="collect_products.html">商品收藏</a>
                    <a class="menuchildItem" href="collect_stores.html">店铺收藏</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="address.html"><span class="icons icon-address"></span>地址管理</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="address.html">地址管理</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="judge.html"><span class="icons icon-evaluate"></span>评价管理</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="judge.html">评价管理</a>
                </div>
            </li>
            <li>
                <a class="menuItem dropBg" href="complain.html"><span class="icons icon-price"></span>申述退款</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="complain.html">申述</a>
                    <a class="menuchildItem" href="refund_money.html">退款</a>
                </div>
            </li>
            <li class="bb0">
                <a class="menuItem dropBg" href="message.html"><span class="icons icon-news"></span>消息中心</a>
                <div class="childMenu">
                    <a class="menuchildItem" href="message.html">消息中心</a>
                </div>
            </li>
        </ul>
        <!--右内容-->
        <div class="menuContent fr">
            <div class="menuConHeader">
                <!--面包屑导航-->
                <div class="breadcrumb">
                    <p>当前位置：
                        <a href="order.html">我的订单</a> &gt;
                        <a class="curPage" href="javascript:;">我的订单</a>
                    </p>
                </div>
            </div>
            <div class="menuConBody">
                <!--筛选-->
                <div class="one_tab">
                    <a class="oneType active_on" href="javascript:;" value="1">交易类商品</a>
                    <a class="oneType " href="javascript:;" value="2">服务类商品</a>
                </div>
                <input type="hidden" id="index">
                <input type="hidden" id="all">
                <input type="hidden" id="page_all">
                <input type="hidden" id="seller_e">
                <!--二次筛选-->
                <div class="sec_tab" style="display: none">
                    <a class="secType active_01" href="javascript:;" all="0">全部订单<span></span></a>
                    <a class="secType" href="javascript:;">待付款<span></span></a>
                    <a class="secType" href="javascript:;">待确认<span></span></a>
                    <a class="secType" href="javascript:;">待退款<span></span></a>
                    <a class="secType" href="javascript:;">待评价<span></span></a>
                    <a class="secType" href="javascript:;">已完成<span></span></a>
                    <a class="secType" href="javascript:;">已取消<span></span></a>
                </div>
                <div class="sec_tab">
                    <a class="secType active_01 name" href="javascript:;" all="0">全部订单<span class="order"></span></a>
                    <a class="secType name" href="javascript:;" all="2">待付款<span class="order"></span></a>
                    <a class="secType name" href="javascript:;" all="4">待确认<span class="order"></span></a>
                    <!-- <a class="secType name" href="javascript:;" all="11">待退款<span class="order"></span></a> -->
                    <a class="secType name" href="javascript:;" all="9">已完成<span class="order"></span></a>
                    <a class="secType name" href="javascript:;" all="10">已取消<span class="order"></span></a>
                </div>
                <div class="productList">
                    <div class="productsListHeader">
                        <span class="ml133">商品信息</span>
                        <span class="ml245">商品金额</span>
                        <span class="ml90">订单状态</span>
                        <span class="ml130">操作</span>
                    </div>
                    <div class="productListBody" id="trade">


                    </div>
                    <!--服务-->
                    <div class="productListBody" id="service">

                    </div>
                    <!--分页-->
                    <div id="page"></div>

                </div>
            </div>
        </div>
    </div>
</div>
<!-- 底部信息 -->

{/block}


{block name="js"}

<script src="_P_/layer/layer.js"></script>

<script src="_JS_/time.js"></script>
<script>

    $(function () {
		var value = decodeURI(window.location.href.split("?")[1]);
        $("#index").val(1);
		if(value == null || value == 2){
			order_service(1);
		}else{
			postfile(1, 1);
		}
        
    });

    $(".name").on('click', function () {
		$('.sec_tab').eq(1).find('.secType').removeClass('active_01');
		$(this).addClass('active_01');
        var index = $("#index").val();
        if (index == '') {
            index = 1;
        }
        $("#all").val($(this).attr('all'));
        postfile(1, index, $(this).attr('all'));
    });

    function postfile(page, index, all) {
        var userinfo = $.cookie('userinfo');
        if (userinfo != null) {
            var user_login = $.base64.decode(userinfo).split(",");
            $.ajax({
                type: 'GET',
                url: "{:url('api/form/trading')}",
                dataType: 'jsonp',
                jsonp: 'callback',
                data: {'uid': user_login[0], 'page': page, 'index': index, 'statuc': all},
                success: function (msg) {
                    if (index == 1) {
                        if (msg.code == 200) {
                            $(".order").eq(0).html(msg.data.all_count);
                            $(".order").eq(1).html(msg.data.count1);
                            $(".order").eq(2).html(msg.data.count2);
                            $(".order").eq(3).html(msg.data.count4);
                            $(".order").eq(4).html(msg.data.count5);
                            $("#trade").html("");
                            if (msg.data.order.length != 0) {
                                for (var i = 0; i < msg.data.order.length; i++) {
									var store = number_format(msg.data.order[i].store, 2, ".", ",");
									var money = number_format(msg.data.order[i].money, 2, ".", ",");
                                    var html = '<div class="listItem" num="' + msg.data.order[i].id + '" all="' + msg.data.order[i].seller_e + '" id="' + msg.data.order[i].image + '" data="' + msg.data.order[i].order + '">' +
                                        '<div class="listItemHeader"><p class="time">' + getMyDate(msg.data.order[i].time * 1000) + '</p>' +
                                        '<p class="orderNo">订单编号：<span>' + msg.data.order[i].order + '</span></p>' +
                                        '<p class="storeName">' + msg.data.order[i].name + '</p></div><div class="listItemBody">' +
                                        '<a class="imgBox" href="/index.php/index/trade/trade_details.html?id=' + msg.data.order[i].name_id + '">' +
                                        '<img src="/Images/tradingMarket/' + msg.data.order[i].image + '"/>' +
                                        '</a><div class="productInfo">' +
                                        '<a class="title moreline" limit="15" href="/index.php/index/trade/trade_details.html?id=' + msg.data.order[i].name_id + '">' + msg.data.order[i].username + '</a>' +
                                        '<span>交易方式：' + msg.data.order[i].trading_name + '</span><span>行业分类：' + msg.data.order[i].market_name + '</span></div><p class="productType">交易类商品</p>' +
                                        '<p class="productPrices prices"><span style="float:left;color:#333">原价：</span>￥' + store + '<br /><span style="float:left;color:#333">报价：</span>￥' + money + '</p><div class="productStatus">';
                                    if (msg.data.order[i].statuc == 1) {
                                        html += '<p class="status">待商家授权</p><a title="查看详情" href="order_details.html?id=' + msg.data.order[i].id + '=1">查看详情</a></div>' +
                                            '<div class="operation"><p class="leftTime">商家授权时间剩余' + msg.data.order[i].shi_time + '</p></div></div></div>';
                                    } else if (msg.data.order[i].statuc == 2 && msg.data.order[i].static != 3) {
                                        html += '<p class="status">商家已授权,待付款</p><a title="查看详情" href="order_details.html?id=' + msg.data.order[i].id + '=1">查看详情</a>' +
                                            '</div><div class="operation"><p class="leftTime">剩余' + msg.data.order[i].shi_time + '</p>' +
                                            '<a class="blue pay" href="pay.html?id=' + msg.data.order[i].id + '&type=1">付款</a>' +
                                            '<a class="red cancel" onclick="cancel_l(this,' + msg.data.order[i].id + ')" href="javascript:;">取消订单</a></div></div></div>';
                                    } else if (msg.data.order[i].statuc == 3 && msg.data.order[i].static != 3) {
                                        html += '<p class="status">已付款，待商家上传文件</p>' +
                                            '<a class="orderDetails" href="order_details.html?id=' + msg.data.order[i].id + '=1">订单详情</a></div>' +
                                            '<div class="operation"></div></div>';
                                    } else if (msg.data.order[i].statuc == 4 && msg.data.order[i].static != 3) {
                                        html += '<p class="status">商家已上传文件，待下载文件</p>' +
                                            '<a class="orderDetails" href="order_details.html?id=' + msg.data.order[i].id + '=1">订单详情</a></div>' +
                                            '<div class="operation">' +
											'<a target="_blank" class="blue download" href="{:url('api/orders/download')}?id='+msg.data.order[i].id+'&type=2"  src="{:url('api/orders/download')}?id='+msg.data.order[i].id+'&type=2" class="download" style="cursor:pointer;">下载文件</a>'+
                                            '</div></div></div>';
                                    } else if (msg.data.order[i].statuc == 5 && msg.data.order[i].static != 3) {
                                        html += '<p class="status">文件下载成功，待确认文件</p>' +
                                            '<a class="orderDetails" href="order_details.html?id=' + msg.data.order[i].id + '=1">订单详情</a></div>' +
                                            '<div class="operation">' +
                                            '<a class="blue confirm" href="javascript:;">确认文件扫描件</a></div></div><div class="listItemFooter">' +
                                            '<a class="appeal" href="javascript:;"><span class="icons icon-appeal"></span>申诉</a>' +
                                            '</div></div>';
                                    } else if (msg.data.order[i].statuc == 6 && msg.data.order[i].static != 3) {
                                        html += '<p class="status">已确认文件，待卖家上传快递单号</p>' +
                                            '<a class="orderDetails" href="order_details.html?id=' + msg.data.order[i].id + '=1">订单详情</a>' +
                                            '</div><div class="operation">' +
                                            '</div></div></div>';
                                    } else if (msg.data.order[i].statuc == 7 && msg.data.order[i].static != 3) {
                                        html += '<p class="status">卖家已邮寄文件，快递运输中，待确认</p>' +
                                            '<a class="orderDetails" href="order_details.html?id=' + msg.data.order[i].id + '=1">订单详情</a>' +
                                            '</div><div class="operation">' +
                                            '<a class="blue check" href="javascript:;">查看快递单号</a>' +
                                            '<a class="blue receive" href="javascript:;">确认收到文件</a></div></div></div>';
                                    } else if (msg.data.order[i].statuc == 9 && msg.data.order[i].static != 3) {
                                        html += '<p class="status">文件已确认接收，订单结束</p>' +
                                            '<a class="orderDetails" href="order_details.html?id=' + msg.data.order[i].id + '=1">订单详情</a></div>' +
                                            '<div class="operation"></div></div></div>';
                                    } else if (msg.data.order[i].statuc == 10 && msg.data.order[i].static != 3) {
                                        html += '<p>买家14个自然日内没有付款，订单取消</p><p><a title="查看详情" href="order_details.html?id=' + msg.data.order[i].id + '">查看详情 </a>' +
                                            '</p></div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].statuc == 11 && msg.data.order[i].static != 3) {
                                        html += '<p>长时间未操作,订单取消</p><p><a title="查看详情" href="order_details.html?id=' + msg.data.order[i].id + '=1">查看详情 </a>' +
                                            '</p></div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].static == 3) {
                                        html += '<p>抱歉,商家已选择其他买家</p><a title="查看详情" href="order_details.html?id=' + msg.data.order[i].id + '=1">查看详情 </a></div></li></ul></div></div></div></div></div></div>';
                                    } else if (msg.data.order[i].statuc == 12 && msg.data.order[i].static != 3) {
                                        html += '<p>买家取消订单</p><a title="查看详情" href="order_details.html?id=' + msg.data.order[i].id + '=1">查看详情 </a></div></li></ul></div></div></div></div></div></div>';
                                    }else if(msg.data.order[i].statuc == 14 && msg.data.order[i].static != 3){
										html += '<p>退款成功，订单结束</p><a title="查看详情" href="order_details.html?id=' + msg.data.order[i].id + '=1">查看详情 </a></div></li></ul></div></div></div></div></div></div>';
									}
                                    $("#trade").append(html);
                                }
                                if (all == 0) {
                                    var king = msg.data.all_count;
                                } else if (all == 2) {
                                    king = msg.data.count1;
                                } else if (all == 4) {
                                    king = msg.data.count2;
                                } else if (all == 9) {
                                    king = msg.data.count4;
                                } else if (all == 10) {
                                    king = msg.data.count5;
                                }
                                if (king == 0) {
                                    $('#page').html('');
                                } else {
                                    $('#page').html(msg.data.render);
                                    $("#pagination").delegate("a", "click", function () {
                                        var index = $("#index").val();
                                        var all = $("#all").val();
                                        if (index == '') {
                                            index = 1;
                                        }
                                        var num = $(this).attr("num");
                                        $("#page_all").val(num);
										
								
                                        if (num) {
                                            postfile(num, index, all);
                                        }
                                    });
									var pages = Math.ceil(msg.data.count / 10);
									$("#GO").on('click',function(){
										var king = $("#go").val();
										if(king > pages){
											layer.alert("最多输入"+pages+"页");
											return;
										}
										postfile(king, index,all);
									});
                                }
                                /*下载合同*/
                                $('.download').on('click', function () {
                                    var id = $(this).parents('.listItem').attr('num');
                                    $.ajax({
                                        type: "get",
                                        url: "/index.php/api/form/trading_download",
                                        data: {
                                            'id': id
                                        },
                                        dataType: 'jsonp',
										beforeSend: function () {
										var index = layer.load(1, {
											shade: [0.1, '#333333'] //0.1透明度的白色背景
										});
										},
                                        success: function (msg) {
                                            layer.closeAll();
                                            if (msg.code == 200) {
                                                
												// var $form = $('<form method="GET"></form>');
												// $form.attr('action', '/status/web/images/contract'+val[i]);
												// $form.appendTo($('body'));
												// $form.submit();
												//var imgUrl = val[i];
												//var $a = $("<a></a>").attr("href", "/Images/contract/" + imgUrl).attr("download", "/Images/contract/" + imgUrl);
												//$a[0].click();
                                                
                                                var page = $("#page_all").val();
                                                var all = $("#all").val();
                                                postfile(page, 1, all);
                                            }
                                            if (msg.code == 1000) {
                                                layer.msg('修改失败！', {icon: 5});
                                            }
                                        }
                                    });
                                });

                                /*确认合同*/
                                $('.confirm').on('click', function () {
                                    var id = $(this).parents('.listItem').attr('num');
                                    $.ajax({
                                        type: "get",
                                        url: "/index.php/api/form/trading_confirm",
                                        data: {
                                            'id': id
                                        },
                                        dataType: 'jsonp',
										beforeSend: function () {
										var index = layer.load(1, {
											shade: [0.1, '#333333'] //0.1透明度的白色背景
										});
										},
                                        success: function (msg) {
                                            layer.closeAll();
                                            if (msg.code == 200) {
                                                var page = $("#page_all").val();
                                                var all = $("#all").val();
                                                postfile(page, 1, all);
                                            }
                                            if (msg.code == 1000) {
                                                layer.msg('修改失败！', {icon: 5});
                                            }
                                        }
                                    });
                                });
                                /*查看快递单号*/
                                $('.check').on('click', function () {
                                    var seller_e = $(this).parents('.listItem').attr('all');
                                    layer.open({
                                        type: 1,
                                        title: '查看快递单号',
                                        closeBtn: false,
                                        shadeClose: true,
                                        scrollbar: false,
                                        content: "<div class='forms' style='width:400px;height:150px;font-size:14px;'>" +
                                        "<div class='form-group' style='margin-bottom:10px;'><label>快递单号：</label>" +
                                        "<span>" + seller_e + "</span></div>",
                                        //	        btn: ['发送', '取消'],
                                        yes: function (index, layero) {
                                            //do something
                                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                                        }
                                    });
                                });

                                /*确认收到文件*/
                                $('.receive').on('click', function () {
								var id = $(this).parents('.listItem').attr('num');
									$.ajax({
										type: "get",
										url: "/index.php/api/form/update_code",
										data:{
											'uid':user_login[0]
										},
										dataType: 'jsonp',
										success: function (msg) {
											layer.closeAll();
											if (msg.code == 200) {
												if(msg.data == null || msg.data == ''){
													layer.msg('支付密码未设置', {icon: 5},function(){
														window.location.href = "{:url('index/person/account')}";
													});
												}else{
													layer.open({
														type: 2,
														title: '确认支付密码',
														fix: false,
														maxmin: true,
														shadeClose: true,
														scrollbar: false,
														area: ['560px', '450px'],
														content: 'update_code.html',
														btn: ['确认', '返回'],
														yes: function(index, layero) {
															var body = layer.getChildFrame('body', index);
															var code=body.find(".code").val();
															if(code==''){
																layer.msg('不能为空！', {icon: 5});
																return false;
															}
															
															$.ajax({
																type: "get",
																url: "/index.php/api/form/check_code",
																data:{
																	'code':code,
																	'uid':user_login[0]
																},
																dataType: 'jsonp',
																success: function (msg) {
																	if (msg.code == 200) {
																		layer.msg(msg.message, {icon: 1},function(){
																			
																			$.ajax({
																				type: "get",
																				url: "/index.php/api/form/trading_receive",
																				data: {
																					'id': id
																				},
																				dataType: 'jsonp',
																				beforeSend: function () {
																				var index = layer.load(1, {
																					shade: [0.1, '#333333'] //0.1透明度的白色背景
																				});
																				},
																				success: function (msg) {
																					layer.closeAll();
																					if (msg.code == 200) {
																						var page = $("#page_all").val();
																						var all = $("#all").val();
																						postfile(page, 1, all);
																					}else{
																						layer.msg(msg.message, {icon: 5});
																					}
																				}
																			});
																			layer.close(index); //如果设定了yes回调，需进行手工关闭
																		});
																	}else{
																		layer.msg(msg.message, {icon: 5});
																	}

																}
															});
														}
													});
												}
											}else {
												layer.msg(msg.message, {icon: 5});
											}
										}
									});
										
                                   
                                });


                                /*申诉*/
                                $('.appeal').on('click', function () {
                                    var order = $(this).parents('div.listItem').attr('data');
                                    var image = $(this).parents('div.listItem').attr('id');
                                    layer.open({
                                        type: 2,
                                        title: '申诉',
                                        fix: false,
                                        maxmin: true,
                                        shadeClose: true,
                                        scrollbar: false,
                                        area: ['720px', '700px'],
                                        content: 'my_appeal.html#' + order,
                                        btn: ['确认申诉', '取消'],
                                        yes: function (index, layero) {
                                            //do something
                                            var body = layer.getChildFrame('body', index);
                                            //body.find("#user_id").val(user_uid);
                                            var formData = new FormData(body.find('form')[0]);
                                            formData.append('uid', user_login[0]);
                                            formData.append('image', "tradingMarket/" + image);
                                            formData.append('order', order);
                                            formData.append('status', 1);
                                            layer.close(index); //如果设定了yes回调，需进行手工关闭
                                            $.ajax({
                                                type: "post",
                                                url: "/index.php/api/form/appeal",
                                                data: formData,
                                                dataType: 'json',
												beforeSend: function () {
												var index = layer.load(1, {
													shade: [0.1, '#333333'] //0.1透明度的白色背景
												});
												},
                                                success: function (msg) {
                                                    layer.closeAll();
                                                    if (msg.code == 200) {
                                                        postfile(page, 1);
                                                    }
                                                    if (msg.code == 1000) {
                                                        layer.msg(msg.message, {icon: 5});
                                                    }
                                                },
                                                contentType: false, //必须false才会自动加上正确的Content-Type
                                                processData: false //必须false才会避开jQuery对 formdata 的默认处理
                                            });
                                        }
                                    });
                                });

                            } else {
                                $("#trade").append('<div class="nodatas"><img src="/static/web/images/nodatas01.png"/>' +
                                    '<p>抱歉，暂无订单</p></div>')
                            }
                        } else {
                            layer.msg('查询失败!', {icon: 1, time: 1000});
                        }
                    } else {

                    }
                }
            })
        } else {
            window.location.href = "{:url('index/login/index')}";
        }
    }

    /*取消订单*/
    function cancel_l(obj, id) {
        layer.open({
            type: 1,
            title: '取消订单',
            closeBtn: false,
            shadeClose: true,
            scrollbar: false,
            content: "<p style='margin:20px 0px;font-size:14px;padding:0 150px 0 20px;'>你确定要取消订单吗？</p>",
            btn: ['确认', '等一等'],
            yes: function (index, layero) {
                //do something
                $.ajax({
                    type: "get",
                    url: "/index.php/api/form/trading_edit",
                    data: {'id': id},
                    dataType: 'jsonp',
                    jsonp: 'callback',
					beforeSend: function () {
					var index = layer.load(1, {
						shade: [0.1, '#333333'] //0.1透明度的白色背景
					});
					},
                    success: function (msg) {
                        layer.closeAll();
                        if (msg.code == 200) {
                            $(obj).parents('.listItem').empty();
                            var page = $("#page_all").val();
                            var index = $("#index").val();
                            if (index == '') {
                                index = 1;
                            }
                            var all = $("#all").val();
                            postfile(page, index, all);
                        }
                        if (msg.code == 1000) {
                            layer.msg("未知错误", {icon: 5});
                        }
                    }
                });
                layer.close(index); //如果设定了yes回调，需进行手工关闭
            }
        });
    }


</script>
<script src="_JS_/order.js"></script>
{/block}


			